<template>
  <el-dialog
    :title="this.dataForm.id ? '修改' : '新增'"
    :close-on-click-modal="false"
    v-model="visible"
    width="80%"
    destroy-on-close
  >
    <el-form
      ref="dataForm"
      :model="dataForm"
      :rules="dataRule"
      label-width="120px"
    >
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="球队名称" prop="name">
            <el-input v-model="dataForm.name" placeholder="球队名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="LOGO URL" prop="logoUrl">
            <el-input
              v-model="dataForm.logoUrl"
              placeholder="LOGO URL"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="评分" prop="rate">
            <el-input v-model="dataForm.rate" placeholder="评分"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="队长名称" prop="teamLeaderName">
            <el-input
              v-model="dataForm.teamLeaderName"
              placeholder="队长名称"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="老板名称" prop="bossName">
            <el-input
              v-model="dataForm.bossName"
              placeholder="老板名称"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template v-slot:footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { request } from "@/utils/axios-util";

export default {
  data() {
    return {
      visible: false,
      dataForm: {},
      dataRule: {
        name: [
          { required: true, message: "球队名称不能为空", trigger: "change" },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    init(row) {
      this.dataForm = { ...row };
      this.visible = true;
    },
    // 更新数据列表
    dataFormSubmit() {
      const data = {
        ...this.dataForm,
      };

      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          const url = "/admin/teamInfo/saveOrUpdate";
          request(url, data, "POST").then(
            (res) => {
              if (res.code === 200) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  },
                });
              } else {
                this.$message.error(res.msg);
              }
            },
            (resp) => {
              this.$message.error("操作失败，", resp);
            }
          );
        }
      });
    },
  },
  emits: ["refreshDataList"],
};
</script>
